package com.cypher.encryptionanddecryption.fragment.dialog;

import android.app.Activity;
import android.content.res.Configuration;
import android.view.Gravity;
import android.view.ViewGroup;

import com.cypher.encryptionanddecryption.R;
import com.cypher.encryptionanddecryption.activity.MainActivity;
import com.cypher.encryptionanddecryption.util.ProgressDialogUtil;

/**
 * 底部DialogFragment
 *
 * @author geyifeng
 * @date 2017/7/28
 */
public class BottomDialogFragment extends BaseDialogFragment {

    private int position;
    private Activity activity;
    public BottomDialogFragment(int position, Activity activity) {
        this.position = position;
        this.activity = activity;
    }

    @Override
    public void onStart() {
        super.onStart();
        mWindow.setGravity(Gravity.BOTTOM);
        mWindow.setWindowAnimations(R.style.BottomAnimation);
        mWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, mWidthAndHeight[1] / 2);
    }

    @Override
    protected int setLayoutId() {
        return R.layout.dialog;
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, mWidthAndHeight[1] / 2);
    }

    @Override
    protected void initView() {
        super.initView();
        switch (position) {
            case 0:
                OtaFragment otaFragment = new OtaFragment();
                if (!otaFragment.isAdded()) {
                    getChildFragmentManager().beginTransaction().add(R.id.dialog_fragment, otaFragment).commitAllowingStateLoss();
                }
                getChildFragmentManager().beginTransaction().show(otaFragment).commitAllowingStateLoss();
                ProgressDialogUtil.dismiss(activity);
                break;
        }
    }
}
